package com.secondriver.url.filter;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.secondriver.url.filter.match.URLPatternMatch;
import com.secondriver.url.filter.urlrealm.Subject
import com.secondriver.url.filter.urlrealm.URLRealm;
import com.secondriver.url.filter.urlrealm.groovy.DefaultURLRealm

class TestSqlQuery {

	private static URLRealm urlRealm;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		def param=[
			url:'jdbc:postgresql://localhost:5432/tomdb',
			user:'postgres',
			password:'postgres',
			driver:'org.postgresql.Driver'
		];
		urlRealm=new DefaultURLRealm(param);
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		urlRealm=null;
	}

	@Before
	public void setUp() throws Exception {
		println('===Test Start===');
	}

	@After
	public void tearDown() throws Exception {
		println('===Test End===');
	}

	@Test
	public void testOpenURL() {
		def urlbeans=urlRealm.buildOpenURLBean();
		urlbeans.each { bean->
			println(bean.toString());
		}
	}

	@Test
	public void testPermitURL(){
		Subject subject=urlRealm.buildSubject([sessionid:'1000', subjectid:'admin']);
		println(subject.toString());
	}

	@Test
	public void testDbConfig(){
		def dbConfig='''url=jdbc:postgresql://localhost:5432/tomdb|user=postgres|password=postgres|driver=org.postgresql.Driver''';
		URLRealm urlRealm=new DefaultURLRealm(dbConfig);
		urlRealm.buildOpenURLBean().each { bean->
			println(bean.toString());
		}
		Subject subject=urlRealm.buildSubject([sessionid:'1001', subjectid:'tom']);
		println(subject.toString());
	}
}
